package com.cardone.platform.authority.controller;

import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cardone.context.Contexts;
import com.cardone.common.dto.PaginationDto;
import com.cardone.common.util.ReturnDataUtils;
import com.cardone.context.ContextHolder;
import com.cardone.platform.authority.dto.UsGroupRoleDto;
import com.cardone.platform.authority.service.UsGroupRoleService;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

/**
* 用户组与角色
*
* @author yaohaitao
*/
@Setter
@Slf4j
@Controller
public class UsGroupRoleController {
/**
* 用户组与角色：删除
*
* @param deleteUsGroupRole
*            用户组与角色对象
* @return 处理结果，json格式
*/
@Deprecated
@RequestMapping(value = { "/authority/usGroupRole/delete.json" }, method = RequestMethod.POST)
@ResponseBody
public Callable<Map<String, Object>> deleteJson(final UsGroupRoleDto deleteUsGroupRole) {
    return () -> {
    ContextHolder.getBean(UsGroupRoleService.class).deleteByIds(deleteUsGroupRole);

    return ReturnDataUtils.newMap();
    };
    }

    /**
    * 用户组与角色：编辑
    *
    * @param findUsGroupRole
    *            用户组与角色对象
    * @return 实体对象集，json格式
    */
    @Deprecated
    @RequestMapping(value = { "/authority/usGroupRole/findById.json" })
    @ResponseBody
    public Callable<Map<String, Object>> findByIdJson(final UsGroupRoleDto findUsGroupRole, final Model model) {
    return () -> {
    final UsGroupRoleDto usGroupRole = ContextHolder.getBean(UsGroupRole
    Service.class).findById(UsGroupRoleDto.class, findUsGroupRole);

    return ReturnDataUtils.newMap("usGroupRole", usGroupRole);
    };
    }

    /**
    * 用户组与角色：分页查询
    *
    * @param paginationUsGroupRole
    *            用户组与角色对象
    * @return 分页，json格式
    */
    @Deprecated
    @RequestMapping(value = { "/authority/usGroupRole/paginationByLikeCode.json" })
    @ResponseBody
    public Callable<Map<String, Object>> paginationByLikeCodeJson(final UsGroupRoleDto paginationUsGroupRole) {
    return () -> {
    final PaginationDto
<UsGroupRoleDto> usGroupRolePagination = ContextHolder.getBean(UsGroupRole
    Service.class).paginationByLikeCode(UsGroupRoleDto.class, paginationUsGroupRole);

    return ReturnDataUtils.newMap("usGroupRolePagination", usGroupRolePagination);
    };
    }

    /**
    * 用户组与角色：分页查询
    *
    * @param paginationUsGroupRole
    *            用户组与角色对象
    * @param model
    *            上下文映射
    */
    @Deprecated
    @RequestMapping(value = { "/authority/usGroupRole/pagination.html" })
    public void paginationHtml(final UsGroupRoleDto paginationUsGroupRole, final Model model) {
    final PaginationDto
<UsGroupRoleDto> usGroupRolePagination = ContextHolder.getBean(UsGroupRole
    Service.class).paginationByLikeCode(UsGroupRoleDto.class, paginationUsGroupRole);

    model.addAttribute("usGroupRolePagination", usGroupRolePagination);
    }

    /**
    * 用户组与角色：分页查询
    *
    * @param findUsGroupRole
    *            用户组与角色对象
    * @param model
    *            上下文映射
    */
    @Deprecated
    @RequestMapping(value = { "/authority/usGroupRole/edit.html" })
    public void editHtml(final UsGroupRoleDto findUsGroupRole, final Model model) {
    final UsGroupRoleDto usGroupRole = ContextHolder.getBean(UsGroupRole
    Service.class).findById(UsGroupRoleDto.class, findUsGroupRole);

    model.addAttribute("usGroupRole", usGroupRole);
    }

    /**
    * 用户组与角色：查询
    *
    * @param findListUsGroupRole
    *            用户组与角色对象
    * @return 用户组与角色对象集合，json格式
    */
    @Deprecated
    @RequestMapping(value = { "/authority/usGroupRole/findListByLikeCode.json" })
    @ResponseBody
    public Callable<Map<String, Object>> findListByLikeCodeJson(final UsGroupRoleDto findListUsGroupRole) {
    return () -> {
    final List<UsGroupRoleDto> usGroupRoleList = ContextHolder.getBean(UsGroupRole
    Service.class).findListByLikeCode(UsGroupRoleDto.class, findListUsGroupRole);

    return ReturnDataUtils.newMap("usGroupRole", usGroupRoleList);
    };
    }

    /**
    * 用户组与角色：保存
    *
    * @param saveUsGroupRole
    *            用户组与角色对象
    * @return 处理结果，json格式
    */
    @Deprecated
    @RequestMapping(value = { "/authority/usGroupRole/save.json" })
    @ResponseBody
    public Callable<Map<String, Object>> saveJson(final UsGroupRoleDto saveUsGroupRole) {
    return () -> {
    ContextHolder.getBean(UsGroupRoleService.class).saveByIdOrCode(UsGroupRoleDto.class, saveUsGroupRole);

    return ReturnDataUtils.newMap();
    };
    }
    }
